package day05Exercise;
import java.util.Scanner;
import java.util.Arrays;

public class Day05StandardExercise02 {
    public static void main(String[] args) {
        /*

1. Addition随机加法运算器

   要求：由系统随机出10道加法题，而后由用户来答题，答题后输出"答对了"或"答错了"，答对1题得10分，答错1题不扣分，最后输出总分数。
   (1)2+19=?
         */
        /*
       int score=0;
        for (int i=1;i<=10;i++){
            int num1=(int)(Math.random()*100);
            int num2=(int)(Math.random()*100);
            System.out.println("("+i+")"+num1+"+"+num2+"=?");//出题
            System.out.println("算吧");

            Scanner scanner1=new Scanner(System.in);
            int answer1=scanner1.nextInt();//答题
            int result1=num1+num2;

            if (answer1==result1){
                System.out.println("答对了");
                score=score+10;

            }else {
                System.out.println("答错了");
            }
        }
        System.out.println("总分："+score);

         */
        /*
        MultiTable九
要求：输出九九乘法表
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6  3*3=9
......
1*9=9 2*9=18 3*9=27........9*9=81
         */

        for (int m = 1; m <= 9; m++) {//行
            for (int n = 1; n <= m; n++) {
                System.out.print(n + "*" + m + "=" + n * m + "\t");//列
            }
            System.out.println();
        }
        //3. 数组小代码练习：声明、初始化、访问、遍历
        //数组的声明
        int[] a1 = new int[10];//声明一个整型数组，有10个整型元素，默认为0

        //数组的初始化
        int[] a2 = {1, 2, 43, 56};

        int[] a3 = new int[]{1, 2, 3, 4, 5};

        int[] a4 = new int[5];
        a4 = new int[]{1, 2, 3, 4, 5};

        int[] a5 = new int[3];//默认值为0

        //访问
        int[] a6 = {1, 4, 6, 7, 8, 9};
        a6[0] = 1;
        a6[2] = 6;
        System.out.println(a6[a6.length - 1]);

        //遍历
        for (int i = 0; i < 6; i++) {
            System.out.print(a6[i] + " ");
        }
        System.out.println();
        //MaxOfArray求数组元素最大值
        int[] a7 = new int[10];
        for (int i = 0; i < 10; i++) {
            a7[i] = (int) (Math.random() * 100);
            System.out.print(a7[i] + " ");
        }
        int max = a7[0];
        for (int i = 1; i < 10; i++) {
            if (a7[i] >= max) {
                max=a7[i];
            }
        }
        System.out.println("最大值为："+max);

        //对数组进行升序排列，并输出排序后的结果
        Arrays.sort(a7);
        System.out.println("排序后的结果：");
        for (int i=0;i<10;i++){
            System.out.print(a7[i]+" ");
        }

    }
}
